home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1996-02-23 | 17.5 KB | 509 lines |
- ' This tutorial is from Mr. AMOS Club issue 5,
- ' edited by Brian Bell and others, which folded
- ' in 1994 with issue 6. No other AMOS group before
- ' or after has matched its code tutorials.
- '
- '*****************************************************************************
- '
- '
- ' WELCOME TO THE ALIEN BREED CLONE
- ' ----------------------------------
- '
- ' Over the next few issues I will be showing YOU how to write a game. Brian
- ' and myself decided that I should show you how to write an Alien Bredd clone,
- ' so here goes...
- '
- ' I know that it doesn't look much like Alien Breed at the minute, but have
- ' patience, once I get some new graphics and a bit of time to work on this
- ' project, you will see a HUGE improvement. Promise.
- '
- ' Okay, the first thing I do when I'm writing a game, is to sit and think
- ' about it for a while, it helps a lot if you are able to identify what
- ' the game has to achieve. To do this I am going to come up with a list of
- ' things that I would like to put in the game, then as the months go by,
- ' I can convert these ideas into code. So the following is a list of ideas
- ' that I have at this early stage, as I attempt each one, I will put my
- ' thoughts about them, and whether they worked as I expected them to.
- '
- ' IDEAS
- ' -------
- '
- ' NUMBER 1 - A MULTI-DIRECTIONAL JOYSTICK CONTROL ROUTINE.
- '
- ' The first thing that I like to write, when producing a game, is the joystick
- ' control routine. That way I can start to get a feel for the game, and have
- ' some feedback about how it's going to work.
- '
- ' As you can see, I have decided that I want the Joystick routine to be
- ' slightly different. Most AMOS games let your player face in four directions
- ' Up, down, left and right, but I want to cater for the four diaganol
- ' directions as well. This results in a bit more work, but the game will
- ' look a lot better for it.
- '
- ' This routine has been implemented, and it works just like I wanted it to,
- ' it has been fully commented so that you can learn from it.
- '
- '
- ' NUMBER 2 - INTELLIGENT COMPUTER-CONTROLLED OPPONENTS.
- '
- ' This is a bit of a challenge. In one of my previous game's, "Kendo's Super
- ' Pong"(KSP), a tennis game, I wanted to have a one-player option. I had to
- ' think of a way to make the computer control the bat, and try to hit the ball,
- ' but obviously he had to be able to be beaten. I thought this would be
- ' really hard to do, but once I sat down and thought about it, I came up with
- ' the solution really quickly.
- '
- ' Remember that all Bobs are displayed on a coordinate system, and so if
- ' we want to make a Bob chase another Bob, all we have to do is fiddle about
- ' with his coordinates until they match. There were other things that had
- ' to be done in KSP to change the computers reaction time, and things like
- ' that, because there were three difficulty levels, but I will be explaining
- ' those fully in the KENDO KOLLECTION.
- '
- ' Anyway, the way that I make the computer-controlled tank home in on the
- ' player is to say something like...
- '
- ' If COMPUTER_TANK_X < PLAYER_TANK_X
- ' Add COMPUTER_TANK_X,SPEED
- ' End If
- '
- ' This would change the X coordinate of the computers tank, until it matched
- ' the players X position.
- '
- ' I hope this makes artificial intelligence a bit easier to understand.
- ' If you have any more ideas about artificial intelligence, or programs
- ' dealing with it then send them in. I'd like to see what other people
- ' have done in this area.
- '
- ' If you are still a bit unsure about Artificial Intelligence, then you can
- ' write to me at the AMOS AGONIES address, in the Club Section. Try and
- ' understand how it works so far, because next month I will be making the
- ' computers tank collide with the scenery, and this will mean that the
- ' intelligence routine will be even more complicated.
- '
- '
- ' NUMBER 3 - A MAPPING SYSTEM.
- '
- ' This will be in next issue's version. In this version, the background is
- ' simply a Packed Picture, but this takes up too much memory, and it isn't
- ' really possible to make the tanks collide with the walls. Next issue the
- ' mapping systen will DEFINITELY be here. I didn't put it in this version
- ' because I don't want to go too fast. The mapping system will be fairly
- ' easy to understand anyway, so even if you have never used mapping before
- ' by the time you have read next months issue YOU should be an EXPERT.
- ' Oh yeah, I'll be using the brand new EFFECT blocks that Brian has built
- ' into MEGA-MAC-MAP, so you can see how to use this EXCELLENT new feature.
- '
- '
- ' NUMBER 4 - A LARGE SCROLLING BACKGROUND.
- '
- ' I'd like to make the playing area a big scrolling background, rather than
- ' have a single-screen flick-screen format. I have been told by loads of
- ' people that this just isn't possible in AMOS, but we'll see...
- '
- '
- ' NUMBER 5 - LOADS OF BADDIES
- '
- ' This will come in at a later stage, when I will hopefully have some
- ' new graphics. I want to have different sorts of aliens running around,
- ' as well as other tanks, and, ooh, loads of different stuff...
- ' Just wait and see.
- '
- ' I will also have a regenerating system for the aliens, where when you
- ' shoot one alien, another one is generated somewhere else, this will give
- ' the appearance of having loads of aliens running around, when we might only
- ' have five or six.
- '
- '
- ' NUMBER 6 - A TWO-PLAYER OPTION
- '
- ' I haven't given this much consideration yet, but it would be easy enough
- ' to have a "versus" mode, where the two tanks are placed on the one screen,
- ' and have to battle each other. It would be good to have two players
- ' fighting the aliens simultaneously, as in the real Alien Breed, but I'm not
- ' sure if AMOS could handle that, without slowing down a lot. It MIGHT work
- ' if I reduce the number of Aliens on screen. I think it would be cool to
- ' have to fight the other player for credits and stuff.
- '
- '
- ' NUMBER 7 - BONUSES
- '
- ' I'll have to come up with a way of scattering bonuses around the game-area,
- ' this shouldn't be too difficult, it will probably be done in a similar way
- ' to Brians Dizzy clone.
- '
- '
- ' Thats all I can think of for the minute, but it's probaly enough to be
- ' going on with ( Understatement ! ). If you have any ideas then you can send
- ' them in to me at the following address, and I'll try to accomadate them
- ' in a future version.
- '
- ' Neil Kennedy
- ' 66 Belmont Church Road
- ' Belfast BT4 3FG
- ' Northern Ireland.
- '
- ' And don't forget that you can also send your AMOS AGONIES to this address.
- '
- '*****************************************************************************
-
- ' ***** Set up the main game screen, and turn off the default settings.
- Screen Open 0,320,256,16,Lowres
- Flash Off : Curs Off : Cls 0 : Hide
-
- ' ***** Load in the graphics, if needed.
- If Length(1)=False
- Load "Tanked_Up_Big_Bobs.Abk"
- End If
-
- ' ***** Load in the background screen, if needed.
- If Length(10)=False
- Load "Tanked_Up_Background_Pic.Abk"
- End If
-
- MAKE_BACKGROUND_SCREEN
-
- ' ***** Switch on Double Buffering, so that there is no flickering.
- Double Buffer
-
-
- '*****************************************************************************
- '
- ' Here, I am declaring some variables as Global variables. This means that
- ' they can be used inside all my procedures, without me having to declare
- ' them as "Shared" inside the individual procedures. Usually I would just
- ' use Shared, but this program is going to be quite big when it's finished,
- ' so its moresensible to declare the variables Globally, so I don't have to
- ' worry about them anymore
- '
- '*****************************************************************************
-
- Global _TANK_1_XPOS,_TANK_1_YPOS,_TANK_1_IMAGE,_TANK_1_SPEED
- Global _TANK_2_XPOS,_TANK_2_YPOS,_TANK_2_IMAGE,_TANK_2_SPEED
-
- ' ***** Set up the defaults for Tank 1.
- _TANK_1_XPOS=300 : _TANK_1_YPOS=200 : _TANK_1_IMAGE=1 : _TANK_1_SPEED=2
- Bob 1,_TANK_1_XPOS,_TANK_1_YPOS,_TANK_1_IMAGE
-
- ' ***** Set up the defaults for Tank 2.
- _TANK_2_XPOS=50 : _TANK_2_YPOS=50 : _TANK_2_IMAGE=11 : _TANK_2_SPEED=1
- Bob 2,_TANK_2_XPOS,_TANK_2_YPOS,_TANK_2_IMAGE
-
-
- ' ***** Now I start the main game loop.
- Repeat
-
- ' ***** Checks for pressing the joystick up, and then checks for the
- ' ***** diagonal directions. It may look complicated at first, but I
- ' ***** have had to write it this way to get the game running at a good
- ' ***** speed.
- If Jup(1)
-
- ' ***** Change the Y-position. Because of the way I have structered
- ' ***** this routine, we only have to change the Y Axis once
- ' ***** whereas it would usually have to be done three times, i.e.
- ' ***** whenever the joystick is pressed up, up-right and up-left.
- Add _TANK_1_YPOS,-_TANK_1_SPEED
-
- ' ***** This bit checks if the player is pushing the joystick up-right.
- If Jright(1)
-
- ' ***** This changes the X position, so that the tank goes up-right.
- ' ***** Then we assign it the correct image
- Add _TANK_1_XPOS,_TANK_1_SPEED
- _TANK_1_IMAGE=6
-
- ' ***** This says, "If the user hasn't pressed the joystick up-right,
- ' ***** then has he pressed it up-left instead ? ", if so then the
- ' ***** next bit of code is executed.
-
- Else
-
-
- If Jleft(1)
-
- Add _TANK_1_XPOS,-_TANK_1_SPEED
- _TANK_1_IMAGE=5
-
- Else
-
- ' ***** If the user hasn't pressed up-right or up-left on the
- ' ***** the joystick, then we know that he MUST have pressed up on
- ' ***** its own, so all we have to do is give the tank the right image.
- ' ***** remember that we have already changed the Y coordinate so that the
- ' ***** tank has moved up the screen, and the tank isn't moving to the
- ' ***** side so we don't need to change the X coordinate.
-
- _TANK_1_IMAGE=1
-
- End If
-
- End If
-
- End If
-
-
- ' ***** This is the checks for pressing the joystick down, it is much the
- ' ***** same as the code for moving the tank upwards. It looks after
- ' ***** the joystick being pressed down, down-right and down-left.
- If Jdown(1)
-
- ' ***** This changes the Y coordinate, so that the tank is moved down
- ' ***** the screen.
- Add _TANK_1_YPOS,_TANK_1_SPEED
-
- ' ***** This checks for the joystick being pressed down-right.
- If Jright(1)
-
- ' ***** Add the speed to the tanks X position, and assign the tank
- ' ***** the image of it facing down-right.
- Add _TANK_1_XPOS,_TANK_1_SPEED
- _TANK_1_IMAGE=7
-
- ' ***** This says, "If the user hasn't pressed the joystick
- ' ***** down-right, then has he pressed it down-left instead ? ",
- ' ***** if so then the next bit of code is executed.
-
- Else
-
-
-
- If Jleft(1)
-
- Add _TANK_1_XPOS,-_TANK_1_SPEED
- _TANK_1_IMAGE=8
-
- Else
-
- ' ***** If the user hasn't pressed down-right or down-left on the
- ' ***** the joystick, then we know that he MUST have pressed down on
- ' ***** its own, so all we have to do is give the tank the right image.
- ' ***** remember that we have already changed the Y coordinate so that the
- ' ***** tank has moved donw the screen, and the tank isn't moving to the
- ' ***** side so we don't need to change the X coordinate.
-
- _TANK_1_IMAGE=3
-
- End If
-
- End If
-
- End If
-
-
-
- '**************************************************************************
- '
- ' Now that we have taken care of moving the tank up, up-right, up-left,
- ' down, down-right and down-left, we have to take care of the two
- ' directions that we haven't dealt with so far. Left and Right.
- '
- ' You may be wondering why I have said below...
- '
- ' If Jright(1) and Jup(1)=false and Jdown(1)=False.
- '
- ' and not
- '
- ' If Jright(1)
- '
- ' Well, this is so that the tank doesn't get moved twice in the same
- ' direction in the same loop. If we pressed up-right on the joystick,
- ' then the tank would be moved up and to the right. But when the program
- ' came down to this part, up-right would also be translated as right on its
- ' own, so the tank would be moved twice to the right, and it would have
- ' the wrong image.
- '
- ' I could have used the "Joy(1)" function, and then checked to see what
- ' number it returned, but this won't do when I have to put in a firing
- ' routine.
- '
- ' TRUST ME I KNOW WHAT I'M DOING. ( I hope )
- '
- ' Uncomment the next line, and comment the line after it if you want
- ' to see what I mean.
- '
- '**************************************************************************
-
- ' If Jright(1)
- If Jright(1) and Jup(1)=False and Jdown(1)=False
- Add _TANK_1_XPOS,_TANK_1_SPEED
- _TANK_1_IMAGE=2
- End If
-
- If Jleft(1) and Jup(1)=False and Jdown(1)=False
- Add _TANK_1_XPOS,-_TANK_1_SPEED
- _TANK_1_IMAGE=4
- End If
-
- ' ***** This calls the procedure that controls the computers tank.
- CONTROL_COMPUTER_TANK
-
- ' ***** This calls the procdure that checks if the tank has gone off the
- ' ***** edges of the screen.
- CHECK_SCREEN_LIMITS
-
- ' ***** Place the bobs on the screen.
-
- ' ***** This is the players tank. It is Bob number 1.
- Bob 1,_TANK_1_XPOS,_TANK_1_YPOS,_TANK_1_IMAGE
-
- ' ***** This is the computers tank. It is Bob number 2.
- Bob 2,_TANK_2_XPOS,_TANK_2_YPOS,_TANK_2_IMAGE
-
-
- ' ***** Wait for the next Vertical Blank, which smooths everything out
- Wait Vbl
-
- ' ***** We repeat this loop until a mouse key is pressed.
- Until Mouse Click
-
- ' ***** The program drops through to here when a mouse button is pressed,
- ' ***** so I just have to close everything down.
-
- ' ***** Fade out the screen.
- Fade 2
- Wait 30
-
- ' ***** Thats it.
- End
-
-
- Procedure CONTROL_COMPUTER_TANK
-
- ' ***** This procedure takes care of moving the computer-controlled tank.
- ' ***** It is basically the same as the code that moves the players
- ' ***** tank, but we don't have any Joystick presses to go on, so we have
- ' ***** to make the computer decide which way the tank is going to go.
-
- ' ***** Check for moving the tank up, up-right and up-left
- If _TANK_2_YPOS>_TANK_1_YPOS
-
- Add _TANK_2_YPOS,-_TANK_2_SPEED
-
- If _TANK_2_XPOS<_TANK_1_XPOS
-
- Add _TANK_2_XPOS,_TANK_2_SPEED
- _TANK_2_IMAGE=16
-
- Else
-
-
- If _TANK_2_XPOS>_TANK_1_XPOS
-
- Add _TANK_2_XPOS,-_TANK_2_SPEED
- _TANK_2_IMAGE=15
-
- Else
-
- _TANK_2_IMAGE=11
-
- End If
-
- End If
-
- End If
-
-
- ' ***** Check for moving the tank down, down-right and down-left
- If _TANK_2_YPOS<_TANK_1_YPOS
-
- Add _TANK_2_YPOS,_TANK_2_SPEED
-
- If _TANK_2_XPOS<_TANK_1_XPOS
-
- Add _TANK_2_XPOS,_TANK_2_SPEED
- _TANK_2_IMAGE=17
-
- Else
-
- If _TANK_2_XPOS>_TANK_1_XPOS
-
- Add _TANK_2_XPOS,-_TANK_2_SPEED
- _TANK_2_IMAGE=18
-
- Else
-
- _TANK_2_IMAGE=13
-
- End If
-
- End If
-
- End If
-
-
- ' ***** Check for moving the tank to the right.
- If _TANK_2_XPOS<_TANK_1_XPOS and _TANK_2_YPOS=_TANK_1_YPOS
-
- Add _TANK_2_XPOS,_TANK_2_SPEED
- _TANK_2_IMAGE=12
-
- End If
-
- ' ***** Check for moving the tank to the left.
- If _TANK_2_XPOS>_TANK_1_XPOS and _TANK_2_YPOS=_TANK_1_YPOS
-
- Add _TANK_2_XPOS,-_TANK_2_SPEED
- _TANK_2_IMAGE=14
-
- End If
-
- ' ***** Phew, that didn't hurt too much did it ? When you run the program
- ' ***** I think that the computer tank looks pretty cool, when you consider
- ' ***** the small amount of code that I had to write to get him moving.
-
- End Proc
-
- Procedure MAKE_BACKGROUND_SCREEN
-
- ' ***** As I said at the start of the program, I am using a Packed Picture
- ' ***** for the the background this month, which means that the tanks can
- ' ***** drive over the walls, when they should really stop. Next issue
- ' ***** will see the introduction of the mapping system.
-
- ' ***** Hide the screen from view.
- Screen Hide 0
-
- ' ***** Unpack the background screen onto screen 0.
- Unpack 10 To 0
-
- ' ***** Turn all the colours to black.
- For LOP=1 To 15
- Colour LOP,$0
- Next LOP
-
- ' ***** Bring screen 0 into view again, but we can't see anything
- ' ***** because all the colours have been turned to black.
- Screen Show 0
-
- ' ***** Now fade the screen in, using the colours from the Sprite bank
- Fade 2 To -1
- Wait 10
-
- End Proc
-
- Procedure CHECK_SCREEN_LIMITS
-
- ' ***** This is just to make sure that the players tank cant go off the
- ' ***** sides of the screen. I don't have to worry about the computer-
- ' ***** controlled tank, because he can't go anywhere that the player
- ' can't go. Sneaky huh ?
-
- If _TANK_1_XPOS>300
- _TANK_1_XPOS=300
- End If
-
- If _TANK_1_XPOS<15
- _TANK_1_XPOS=15
- End If
-
- If _TANK_1_YPOS<20
- _TANK_1_YPOS=20
- End If
-
- If _TANK_1_YPOS>220
- _TANK_1_YPOS=220
- End If
-
-
- End Proc